(function () {
	var ns = ij.pkg('core').namespaceString;
	ij.core.Container = ij.core.DisplayObject.extend({
		init: function (config) {
			return this._super(ij.apply({
				classname: ns +'.Container',
				renderer: {
					classname: 'ij.core.ContainerDomRenderer'
				},
				objects: [],
				classes: ['ij-object', 'ij-container']
			}, config));
		},
		apply: function (extension, overwrite_existing) {
			var objects = [],
			config = ij.clone(extension);
			if (config && config.objects) {
				objects = config.objects;
				if (this.objects) {
					delete config.objects;
				} else {
					config.objects = [];
				}
			}
			
			this._super(config, overwrite_existing);
			
			objects.each(function (i, item) {
				this.add(item);
			}, this);
		},
		render: function () {
			this._super();
			
			ij.each(this.objects, function (i, obj) {
				obj.render();
			}, this);
			return this;
		},
		update: function () {
			this._super();
			
			ij.each(this.objects, function (i, obj) {
				obj.update();
			}, this);
			return this;
		},
		add: function (object) {
			if (object) {
				var i;
				if (!(object instanceof ij.core.DisplayObject)) {
					object = new ij.core.DisplayObject(ij.apply(ij.clone(object), {
						parent: this
					}));
					i = -1;
				} else {
					i = this.objects.indexOf(object);
				}
				
				if (i == -1) {
					object.parent = this;
					this.objects.push(object);
					
					this.dispatchEvent(new Event({
						name: 'add',
						object: object
					}));
				}
			}
			
			return this;
		}
	});
})();